package org.despair2D.net 
{
	
	import com.bit101.components.PushButton;
	import flash.display.Sprite;
	import flash.events.IOErrorEvent;
	import flash.events.MouseEvent;
	import flash.events.NetStatusEvent;
	import flash.events.SecurityErrorEvent;
	import flash.net.NetConnection;
	import flash.net.Responder;
	import com.adobe.crypto.MD5
	import org.despair2D.Despair;
	
//static public var BASIC_URL:String = "http://app100679243.qzoneapp.com/texas.poker.com/";/*AMFPHP网关地址*/
		//static public var PHP_URL:String = "http://app100679243.qzoneapp.com/texas.poker.com/index.php?m=gw";
public class NetConnectDemo extends Sprite
{
	
	private var m_url:String = 'http://app100679243.qzoneapp.com/texas.poker.com/index.php?m=gw'
	public function NetConnectDemo() 
	{
		nc = new NetConnection()
		//trace(nc.objectEncoding)
		trace(nc.connected)
		
		nc.objectEncoding = 3
		nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, se)
		nc.addEventListener(IOErrorEvent.IO_ERROR, ioe)
		nc.addEventListener(NetStatusEvent.NET_STATUS, ns)
		nc.connect(m_url)
		
		var pb:PushButton = new PushButton(this, 100, 100, 'send')
		pb.addEventListener(MouseEvent.CLICK, click)
	}
	private var nc:NetConnection
	private function click(e:MouseEvent):void
	{
		//trace(nc.connected)
		var req:Object = { };
		//req["uid"] = 73
		//req["pfid"] = 0
		//req["usid"] = 2
		//req["param"] = [44,"8f1dfdf2996a3f815a24d735d7787a9c"];
		//req["mkey"] = 'c071fb30faa4d46f097fa85b5074e185'
		//req["lang"] = 0
		//req["time"] = uint(new Date().valueOf() / 1000);
		//req["sign"] = MD5.hash(joins(req , req["mkey"]));
		//var paras:Array = ['System.login',new Responder(result, staus),req]
		
		nc.call('System.login',new Responder(result, staus),req)
	}
	
	private function result(result:Object):void
	{
		//trace('result')
		var xml:XML = Despair.debugger.toXML(result)
		trace(xml)
	}
		
	private function staus(errorInfo:Object):void
	{
		trace('staus')
	}
	
	protected function se(e:SecurityErrorEvent):void 
	{
		//throw new Error(e.toString());
		trace('se')
	}
	protected function ioe(e:IOErrorEvent):void 
	{
		//throw new Error(e.toString());
		trace('ioe')
	}
	protected function ns(e:NetStatusEvent):void 
	{
		//throw new Error(e.toString());
		//dispatchEvent(new Event(ERROR));
		trace(e.info.code)
	}
}

}
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.net.FileReference;
import flash.utils.ByteArray;
function joins(arg:Object , mkey:String):String
{
	var str:String = "AS";
	if (!(arg is ByteArray || arg is FileReference || arg is BitmapData || arg is Bitmap))
	{
		
		if (arg is Boolean || arg == null)
		{
			str += "";
		}
		else if ( arg is String || arg is Number )
		{
			str += "X" + mkey + arg.toString();
		}
		else
		{
			var keys:Array = [];
			for (var key:Object in arg)
			{
				keys.push(key);
			}
			keys.sort();
			for (var i:int = 0; i < keys.length; i++) 
			{
				str += ( keys[i] + '=' + joins(arg[keys[i]], mkey));
			}
		}
	}
	return str;
}